package com.lry.web.video.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lry.web.video.entity.VideoChapter;
import com.lry.web.video.mapper.VideoChapterMapper;
import com.lry.web.video.service.VideoChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@Service
public class VideoChapterServiceImpl implements VideoChapterService {
    @Autowired
    VideoChapterMapper videoChapterMapper;

    public int setVideoChapter(VideoChapter videoChapter) {
        int insert = videoChapterMapper.insert(videoChapter);
        return insert;
    }

    public List<VideoChapter> getVideoChapters(String videoId) throws IOException {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_id",videoId);
        List<VideoChapter> videoChapters = videoChapterMapper.selectList(wrapper);
        return videoChapters;

    }



    public int deleteByVVId(String vVId) throws Exception {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("video_variable_id",vVId);
        return videoChapterMapper.delete(wrapper);
    }

    public int deleteByVideoId(String videoId) throws Exception {
        List<String> listVId = Arrays.asList(videoId.split(","));
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.in("video_id",listVId);
        return videoChapterMapper.delete(wrapper);
    }


}

